package com.supermap.business.user;

import com.alibaba.dubbo.config.annotation.Reference;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dataservice.util.Table;
import com.supermap.dubbo.api.user.UserTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lxs
 * @Title:服务对象 接口层
 * @Description:
 * @date 2018/7/26  17:02
 */
@Controller
@RequestMapping("UserTypeController")
public class UserTypeController {
    /**
     * 使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(UserTypeController.class);
    @Reference(timeout = 10000)
    private UserTypeService userTypeService;

    /**
     * 获取角色类型
     * @return
     */
    @RequestMapping("getRoleList")
    @ResponseBody
    public JSONUtil getRoleList(){
        return userTypeService.getRoleList();
    }

    /**
     * 根据areacodehe角色code获取全部对象
     * @return
     */
    @RequestMapping("getUserTypeList")
    @ResponseBody
    public JSONUtil getUserTypeList(HttpServletRequest request){
        String areaCode=request.getParameter("areaCode");
        String code=request.getParameter("code");
        return userTypeService.getUserTypeList(areaCode,code);
    }

    /**
     * 根据ID 获取详细的VIP信息
     * @return
     */
    @RequestMapping("getVipById")
    @ResponseBody
    public JSONUtil getVipById(HttpServletRequest request){
        String id=request.getParameter("id");
        return  userTypeService.getVipById(id);
    }

    /**
     * 根究ID 获取User
     * @param request
     * @return
     */
    @RequestMapping("getUserById")
    @ResponseBody
    public JSONUtil getUserById(HttpServletRequest request){
        String id=request.getParameter("id");
        return  userTypeService.getUserById(id);
    }

    /**
     * 根据userId修改epath
     * @return
     */
    @RequestMapping("updateEpathByUserId")
    @ResponseBody
    public JSONUtil updateEpathByUserId(HttpServletRequest request){
        String epath = request.getParameter("epath");
        String userId = request.getParameter("userId");
        return  userTypeService.updateEpathByUserId(epath,userId);
    }

    /**
     * 根据areaCode获取专家信息分页显示
     * @param request
     * @param table
     * @return
     */
    @RequestMapping("getEXPERTListByareaCode")
    @ResponseBody
    public Table getEXPERTListByareaCode(HttpServletRequest request,Table table){
        String areaCode=request.getParameter("areaCode");
        String subjectId=request.getParameter("subjectId");
        JSONUtil jsonUtil = userTypeService.getEXPERTListByareaCode(table,areaCode,subjectId);
        table =(Table)jsonUtil.getData();
        table.setMsg(jsonUtil.getMsg());
        table.setCode(jsonUtil.getCode());
        return table;
    }
}
